class HomeController < ApplicationController
  before_filter :authenticate_user! , :only => [ :profile, :mybooks]
  def index
    @books=Book.all
    @book_types=BookType.all
  end
  def type
    @books=Book.where(["book_type_id=#{params[:id]}" ])
  end
  def tintuc

  end
  def lienhe

  end
  def profile
    @user=User.find(current_user.id)
  end
  def mybooks
    @borrow_book=BorrowBook.where(["user_id=#{current_user.id}"])
  end
  def update
    @user = User.find(current_user.id)
    @user.update_attributes(params[:user])
    @user.save
    flash[:notice]="Profile was updated successfully"
    render "index"
  end
  def search
    @books=Book.where(["name LIKE \"#{params[:key]}\"OR author LIKE \"#{params[:key]}\" OR publisher like \"#{params[:key]}\" "])
    #OR author LIKE #{params[:key]} OR publisher like #{params[:key]}     a
  end
end
